
import axios from 'axios'

function addItems(config){
  if(config==null){
    config={}
  }
  config["x-micro-secure"]="DUsGRgBYJhjpN7tb";
  config["x-auth-token"]= sessionStorage.sessionId;
}

function enhandBody(data){
  let req={};
  req.body=data;
  return req;
}

function enhandPageQueryBody(data){
   if(data==null){
     data={}
   }
   if(data.params==null){
     data.params=[{"name":"sEcho","value":"1"},{"name":"iDisplayStart","value":"0"}  ,{"name":"iDisplayLength","value":"2000"}];
   }
   return enhandBody(data);
}

export default {
    login: (arg,config)=>axios.post('security/login',arg,config),//登录

    menuTree:(configure)=>{
      addItems(configure)
      return axios.get('ubm/menu/tree',null,configure)
    },
    //菜单列表
    listMenu:(configure)=>{
      addItems(configure)
      return axios.post('ubm/menu/items2',enhandPageQueryBody(null),configure)
    },
    //菜单树
    listMenuTree:(data,configure)=>{
      addItems(configure)
      return axios.post('ubm/menu/tree/all',enhandPageQueryBody(data),configure)
    },
    //修改菜单
    updMenuItem:(data,configure)=>{
      addItems(configure)
      return axios.patch('ubm/menu/item',enhandBody(data),configure)
    },
    //新增菜单
    addMenuItem:(data,configure)=>{
      addItems(configure)
      return axios.post('ubm/menu/item',enhandBody(data),configure)
    },

    deletMenuItem:(data,configure)=>{
       addItems(configure)
       return axios.delete('ubm/menu/'+data,configure)
    },

    //恢复菜单
    enableMenuItem:(data,configure)=>{
      addItems(configure)
      return axios.patch('ubm/menu/'+data,configure)
    },

    //用户列表
    queryUsers:(data,configure)=>{
      addItems(configure)
      return axios.post('ubm/user/list',enhandBody(data),configure)
    },

    //重置用户密码
    resetUserPwd:(data,configure)=>{
      addItems(configure)
      return axios.patch('ubm/user/password/'+data,configure)
    },

    //新增用户
    addUser:(data,configure)=>{
      addItems(configure)
      return axios.post('ubm/user/add',enhandBody(data),configure)
    },

    //编辑用户
    updUser:(data,configure)=>{
      addItems(configure)
      return axios.patch('ubm/user/modify',enhandBody(data),configure)
    },

    //删除用户
    deleteUser:(data,configure)=>{
      addItems(configure)
      return axios.delete('ubm/user/'+data,configure)
    },

    //公司树
    treeCompany:(data,configure)=>{
      addItems(configure)
      return axios.post('ubm/company/tree/all',enhandPageQueryBody(data),configure)
    }

}


